package com.netdisk.mapper;

import com.netdisk.dto.UserActivityDTO;
import com.netdisk.entity.User;
import com.netdisk.entity.UserActivity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from users where username = #{username};")
    User findByUsername(String username);

    /**
     * 根据邮箱查询用户
     * @param email
     * @return
     */
    @Select("select * from users where email = #{email};")
    User findByEmail(String email);


    /**
     * 根据用户ID查询用户
     * @param id
     * @return
     */
    @Select("select * from users where id = #{id};")
    User findById(Integer id);

    @Select("select count(*) from files where user_id = #{id};")
    Integer countFiles(Integer id);

    /*记录用户操作*/
    void insertActivity(UserActivityDTO userActivityDTO);

    /*获取前10条用户操作*/
    @Select("select * from user_activities where user_id = #{userId} limit 10")
    List<UserActivity> getActivityList(Integer userId);

    void insert(User user);

}
